<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
</head>
<style>
body{background-color:#eee;}
p{height:5000px;}
/*main*/
#toTop{
	display:none;
	position:fixed;
	right:20px;
	bottom:20px;
	border:1px solid #9CF;
	background-color:#CFF;
	cursor:pointer;
}
</style>
<script src="jquery-1.10.1.min.js"></script>
<body>
<nav>菜单</nav>
<div id="toTop">返回顶部</div>
<p></p>
</body>
<script>
/*//jquery
$(window).scroll(function(){
	var top=$(this).scrollTop(),
		toTop=$('#toTop');
	top>0?toTop.show():toTop.hide();
})
$('#toTop').click(function(){
	$('body,html').animate({scrollTop:0} ,600);
})*/

//js
var toTop=document.getElementById('toTop');
window.onscroll=function(){
	var top=document.documentElement.scrollTop || document.body.scrollTop;
	top>0?toTop.style.display='block':toTop.style.display='none';	
}
toTop.onclick=function(){
	var top=document.documentElement.scrollTop || document.body.scrollTop;
	//var t=setInterval(function(){if(top>0){document.body.scrollTop-=30;}},1)
	document.documentElement.scrollTop=0;
	document.body.scrollTop=0;
}
clearInterval(t);
</script>
</html>
